﻿　
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using SHKF.B2C.MeiTuanShanGou.BLL;　
using SHKF.B2C.BLL.Center;　
using SHKF.B2C.MeiTuanShanGou.Model.Dto.Center;
using SHKF.B2C.MeiTuanShanGou.Model.Dto.Medicine;
using SHKF.B2C.MeiTuanShanGou.Model.Dto.Token;　
using SHKF.B2C.MeiTuanShanGou.Model.Entity.Medicine;
using SHKF.B2C.MeiTuanShanGou.Network;
using SHKF.B2C.Model;
using SHKF.B2C.Model.Dto;
using SHKF.B2C.Model.Dto.Center;
using SHKF.B2C.Model.Entity.Center;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace SHKF.B2C.MeiTuanShanGou.Service.Controllers
{
    [Route("[controller]")]
    [ApiController]
    public class ProductController : Base2Controller
    {  
        private readonly MedicineBLL medicineBLL; 
       
        private readonly ShopMapBLL shopMapBLL;
          
        public ProductController(  
            MedicineBLL medicineBLL,
            ShopMapBLL shopMapBLL, 
            IServiceProvider serviceProvider,
            ILogger<ProductController> logger) : base(serviceProvider, logger)
        {  
            this.medicineBLL = medicineBLL; 
            this.shopMapBLL = shopMapBLL;
        }

        /// <summary>
        /// 更新价格
        /// </summary>
        /// <param name="price"></param>
        /// <returns></returns>
        [HttpPost("Price")]
        public async Task<MedicinePriceDto> UpdatePrice(UpdateProductPrice price)
        {
            MedicinePriceDto dto = new MedicinePriceDto(); 
            List<ShopMapEntity> shops = this.shopMapBLL.Query(price.ShopSN, PlatformEnum.Mtsg);
            if(shops == null)
            {
                dto.error = new Error() { code = -1, msg = $"{price.ShopSN}没有配置美团闪购SN" };
                return dto;
            }

            long app_poi_code = shops[0].app_poi_code;
            //MedicinePrice medicinePrice = new MedicinePrice();
            //medicinePrice.app_poi_code = app_poi_code.ToString();

            List < MedicinePriceData > list = new List<MedicinePriceData>();
            //medicinePrice.medicine_data = list;

            foreach (ProductPrice productPrice in price.Data)
            {
                MedicinePriceData data = new MedicinePriceData();
                data.price = productPrice.price;

                ProductInfoMtsgEntity productInfoEntity = this.medicineBLL.Get(productPrice.ProductSN, price.ShopSN); 
                data.app_medicine_code = productInfoEntity.ID; //暂时用ID,以后合在在一起用虚拟ProductSN查找

                list.Add(data);
            }
            httpClientMeiTuanShanGou.GetTimeStamp();

            TokenMeiTuanDto token = await this.GetMtsgToken(app_poi_code);
            if (token.status != 0)
            {
                return dto;
            }

            
            dto = await httpClientMeiTuanShanGou.BatchUpdatePrice(list);

            return dto;
        }
         
        [HttpPost("save")]
        public async Task<DataDto> Save(ProductInfoMtsgReq product)
        {
            //从Erp向平台
            DataDto dto = new DataDto();

            try
            {
                //upc
                if (string.IsNullOrEmpty(product.Upc))
                {
                    dto.error = new Error() { msg = "药品UPC码不能为空" };
                    return dto;
                }

                string msg = "";
                foreach (long ShopSN in product.ShopList)
                {
                    List<ShopMapEntity> shops = this.shopMapBLL.Query(ShopSN, "");
                    if (shops == null || shops.Count == 0)
                    { 
                        msg += $"请在B2C平台创建虚拟商店 {product.ShopSN}";
                        continue;
                    }
                     
                    //美团闪购
                    DataDto dtoMtsg = await this.SaveMtsg(product, shops);
                    if (dtoMtsg.error != null)
                    {
                        msg +=　$"虚拟店铺{ShopSN}" + dtoMtsg.error.msg;
                    }

                    //饿了么 
                    //DataDto dtoEleme = await this.SaveEleme(product, shops);
                    //if (dtoEleme.error != null)
                    //{
                    //    msg += dtoEleme.error.msg;
                    //} 
                }

                if (msg != "")
                {
                    dto.error = new Error();
                    dto.error.msg = msg;
                    dto.error.code = -1;
                }
                else
                {
                    // this.productInfoBLL.Save(product);
                }
            }
            catch (Exception ex)
            {
                dto = new DataDto();
                dto.SetException(ex);
            }
            return dto;
        }

        [HttpPost("isSoldOut")]
        public async Task<IsSoldOutResultDto> IsSoldOut(IsSoldOut isSoldOut)
        {
            // 药品批量上下架
            IsSoldOutResultDto dto = new IsSoldOutResultDto();
            try
            {
                string msg = "";
                foreach(long ShopSN in isSoldOut.ShopSN)
                {
                    List<ShopMapEntity> shops = this.shopMapBLL.Query(ShopSN, "");
                    if (shops == null || shops.Count == 0)
                    {
                        msg = "请创建虚拟商店{ShopSN}";
                        continue;
                    }

                    //美团闪购
                    ShopMapEntity shopEntity = shops.Where(ww => ww.Platform == PlatformEnum.Mtsg).First();
                    dto = await IsSoldOutMtsg(isSoldOut, shopEntity.app_poi_code);
                } 

                if(msg != "")
                {
                    dto.error = new Error() { msg = "请创建商店" }; 
                }

                return dto;
            }
            catch (Exception ex)
            {
                dto.error = new Error() { code = -1, msg = ex.Message };
                return dto;
            }　
        }

        [HttpGet("list")]
        public async Task<MedicineListDto> MtsgList(int shopSN, string Upc)
        {
            //绑定前美团闪购的药品列表
            MedicineListDto dto = new MedicineListDto();

            try
            {
                ShopMapEntity shopCEntity = this.shopMapBLL.Get(shopSN, PlatformEnum.Mtsg);
                if (shopCEntity == null || shopCEntity.app_poi_code == 0)
                {
                    dto.error = new Error() { code = -1, msg = $"门铺:{shopSN}的 app_poi_code不能为空" };
                    return dto;
                }
                long app_poi_code = shopCEntity.app_poi_code;

                TokenMeiTuanDto token = await this.GetMtsgToken(app_poi_code);
                if (token.status != 0)
                {
                    dto.error = new Error() { code = token.status, msg = token.message };
                    return dto;
                }

                //获取数据库中已经绑定的
                this.medicineBLL.platform = PlatformEnum.Mtsg;
                List<ProductInfoMtsgEntity> productList = this.medicineBLL.Query(app_poi_code);

                this.httpClientMeiTuanShanGou.GetTimeStamp();

                int total = 0;
                int offset = 0;
                int pageSize = 200;
                do
                {
                    MedicineListDto medicinesList = await this.httpClientMeiTuanShanGou.GetMedicineList(offset, pageSize);

                    if (medicinesList != null)
                    {
                        if (medicinesList.error != null)
                        {
                            dto.error = medicinesList.error;
                        }
                        else
                        {
                            if (medicinesList.extra_info != null && medicinesList.data != null && medicinesList.data.Count > 0)
                            {
                                total = medicinesList.data.Count;
                                if (total > 0)
                                {
                                    offset += total;

                                    //过滤掉已经绑定的
                                    List<MedicineInfo> data2 = medicinesList.data.FindAll(ww=>ww.upc.Contains(Upc));

                                    foreach (MedicineInfo medicineInfo in data2)
                                    {
                                        bool bExist = false;
                                        if (productList != null && productList.Count > 0)
                                        {
                                            var list = productList.Where(oo => oo.Upc == medicineInfo.upc);
                                            if (list != null && list.Count() > 0)
                                            {
                                                bExist = true;
                                            }
                                        }

                                        if (!bExist) //如果没有绑定
                                        {
                                            medicineInfo.app_poi_code = app_poi_code;
                                            dto.data.Add(medicineInfo);

                                            if(!string.IsNullOrEmpty(Upc))
                                            {
                                                //如果Upc不为空的话，直接返回，以后的不需要循环
                                                return dto;
                                            }
                                        }
                                    }
                                }
                            }
                        }

                    }

                } while (total == pageSize);

                //过滤掉已经绑定的

            }
            catch (Exception ex)
            {

                throw ex;
            }

            return dto;
        }

        [HttpPost("binding")]
        public DataDto MtsgBinding(ProductInfoMtsgEntity product)
        {
            // 绑定药

            DataDto dto = new DataDto();

            try
            {
                //检查必须填项
                if (product.ProductSN == 0)
                {
                    dto.error = new Error() { msg = "Erp产品SN不能为空" };
                    return dto;
                }

                //upc
                if (string.IsNullOrEmpty(product.Upc))
                {
                    dto.error = new Error() { msg = "药品UPC码不能为空" };
                    return dto;
                }

                if (string.IsNullOrEmpty(product.ID))
                {
                    dto.error = new Error() { msg = "药品编码不能为空" };
                    return dto;
                }

                List<ShopMapEntity> shops = this.shopMapBLL.Query(product.ShopSN, "");
                if (shops == null || shops.Count == 0)
                {
                    dto.error = new Error() { msg = "请创建商店" };
                    return dto;
                }

                ShopMapEntity shop = shops.Where<ShopMapEntity>(ww => ww.Platform == PlatformEnum.Mtsg).First();
                if(shop == null)
                {
                    dto.error = new Error() { msg = "美团闪购没有维护店铺信息" };
                    return dto;
                }
                 
                int ShopSN = shop.ShopSN;
                int CompanySN = shop.CompanySN;

                string msg = "";

                //美团闪购
                //if (product.ShopSN == 0)
                //{
                //    ShopMapEntity shop = shops.Where<ShopMapEntity>(ww => ww.Platform == PlatformEnum.Mtsg).First();
                //    if (shop != null)
                //    {
                //        product.ShopSN = shop.ShopSN;
                //        product.CompanySN = shop.CompanySN;
                //        int result = this.medicineBLL.Save(product);
                //    }
                //    else
                //    {
                //        msg += "美团闪购没有维护店铺信息";
                //    }
                //}
                //else
                //{
                //    int result = this.medicineBLL.Save(product);
                //}

                product.CompanySN = CompanySN;
                int result = this.medicineBLL.Save(product);

                if (msg != "")
                {
                    dto.error = new Error();
                    dto.error.msg = msg;
                }
            }
            catch (Exception ex)
            {
                DataDto error = new DataDto()
                {
                    data = "ng",
                    error = new Error() { msg = ex.Message }
                };
                return error;
            }
            return dto;
        }

        [HttpPost("batchbinding")]
        public DataDto MtsgBatchBinding(List<ProductInfoMtsgEntity> products)
        {
            // 绑定药

            DataDto dto = new DataDto();

            try
            {
                string msg = "";
                foreach (ProductInfoMtsgEntity product in products)
                {
                    //检查必须填项 
                    msg = VerifyProduct(product);
                    if (msg != "")
                    {
                        continue;
                    }

                    List<ShopMapEntity> shops = this.shopMapBLL.Query(product.ShopSN, "");
                    if (shops == null || shops.Count == 0)
                    {
                        msg += $"请创建商店:{product.ShopSN}";
                        continue;
                    }

                    //美团闪购 
                    ShopMapEntity shop = shops.Where<ShopMapEntity>(ww => ww.Platform == PlatformEnum.Mtsg).First();
                    if (shop != null)
                    {
                        if (product.ShopSN == 0)
                        {
                            product.ShopSN = shop.ShopSN;
                        }
                        product.CompanySN = shop.CompanySN;
                        int result = this.medicineBLL.Save(product);
                    }
                    else
                    {
                        msg += "美团闪购没有维护店铺信息";
                    }
                }

                if (msg != "")
                {
                    dto.error = new Error();
                    dto.error.msg = msg;
                }
            }
            catch (Exception ex)
            {
                DataDto error = new DataDto()
                {
                    data = "ng",
                    error = new Error() { msg = ex.Message }
                };
                return error;
            }
            return dto;
        }

        [HttpPost("Stock")]
        public async Task<DataDto> Stock(UpdateStock Stock)
        {
            //更新库存
            DataDto dto = new DataDto();
            try
            {
                if (Stock.StockList.Count > 200)
                {
                    dto.error = new Error() { code = -1, msg = "可传药品库存数据限定不超过200组" };
                    return dto;
                }

                List<ShopMapEntity> shopList = this.shopMapBLL.Query(Stock.ShopSN, "");
                if (shopList == null || shopList.Count == 0)
                {
                    dto.error = new Error() { code = -1, msg = "请创建门门" };
                    return dto;
                }

                string strMsg = "";
                //美团闪购 
                DataDto dtoMtsg = await this.UpdateMtsgStock(shopList, Stock.StockList);
                if (dtoMtsg.error != null)
                {
                    strMsg += dtoMtsg.error.msg;
                }

                if (strMsg != "")
                {
                    dto.error = new Error() { code = -1, msg = strMsg };
                }
            }
            catch (Exception ex)
            {
                DataDto error = new DataDto()
                {
                    data = "ng",
                    error = new Error() { msg = ex.Message }
                };
                return error;
            }
            return dto;
        }

        [HttpPost("unbinding")]
        public async Task<DataDto> UnBinding(UnBindingProduct stock)
        {
            //删除绑定
            DataDto dto = new DataDto();
            try
            {

                List<ShopMapEntity> shopList = this.shopMapBLL.Query(stock.ShopSN, "");
                if (shopList == null || shopList.Count == 0)
                {
                    dto.error = new Error() { code = -1, msg = $"请创建门店{stock.ShopSN}" };
                    return dto;
                }

                string strMsg = ""; 

                //美团闪购 
                foreach (ShopMapEntity shop in shopList)
                {
                    this.medicineBLL.platform = shop.Platform;
                    foreach (int ProductSN in stock.ProductList)
                    {
                        ProductInfoMtsgEntity mtsgInfo = this.medicineBLL.Get(ProductSN, stock.ShopSN);
                        if (mtsgInfo != null)
                        {
                            long app_poi_code = shop.app_poi_code;

                            int result = this.medicineBLL.Delete(app_poi_code, ProductSN);
                            if (result == 0)
                            {
                                strMsg += $":app_poi_code{app_poi_code} ProductSN:{ProductSN} 在数据中不存在";
                            }

                            if( stock.IsDeletePlat)
                            {
                                string strMtsgMsg = "";
                                TokenMeiTuanDto token = await this.GetMtsgToken(app_poi_code);
                                if (token == null)
                                {
                                    strMtsgMsg = "token不能为空";
                                }

                                if (string.IsNullOrEmpty(token.access_token))
                                {
                                    strMtsgMsg = token.message;
                                }

                                if (strMtsgMsg == "")
                                {
                                    this.httpClientMeiTuanShanGou.GetTimeStamp();

                                    //删除药品
                                    DataDto dtoDelete = await this.httpClientMeiTuanShanGou.MedicineDelete(app_poi_code, mtsgInfo.app_medicine_code);
                                    if (dtoDelete.error != null)
                                    {
                                        strMsg += dtoDelete.error.msg;
                                    }
                                }
                            } 
                        }
                    }
                }

                if (strMsg != "")
                {
                    dto.error = new Error() { code = -1, msg = strMsg };
                }
            }
            catch (Exception ex)
            {
                DataDto error = new DataDto()
                {
                    data = "ng",
                    error = new Error() { msg = ex.Message }
                };
                return error;
            }
            return dto;
        }

        #region mtsg

        private string VerifyProduct(ProductInfoMtsgEntity product)
        {
            string msg = "";
            if (product.ProductSN == 0)
            {
                msg += "Erp产品SN不能为空 ";
            }

            //upc
            if (string.IsNullOrEmpty(product.Upc))
            {
                msg += "药品UPC码不能为空 ";
            }

            if (string.IsNullOrEmpty(product.ID))
            {
                msg += "药品编码不能为空 ";
            }

            return msg;
        }

        private async Task<IsSoldOutResultDto> IsSoldOutMtsg(IsSoldOut isSoldOut, long app_poi_code)
        {
            IsSoldOutDto isSoldOutDto = new IsSoldOutDto();
            isSoldOutDto.app_poi_code = app_poi_code;
            isSoldOutDto.medicine_data = new List<MedicineData>();
            foreach (ProductData productData in isSoldOut.ProductData)
            {
                string id = this.medicineBLL.GetID(productData.ProductSN, app_poi_code);

                isSoldOutDto.medicine_data.Add(
                    new MedicineData()
                    {
                        app_medicine_code = id,
                        is_sold_out = productData.is_sold_out
                    });
            }

            IsSoldOutResultDto dto = new IsSoldOutResultDto();

            //检查必须填项
            this.httpClientMeiTuanShanGou.app_poi_code = isSoldOutDto.app_poi_code;
            if (this.httpClientMeiTuanShanGou.app_poi_code == 0)
            {
                dto.error = new Error() { code = -1, msg = "app_poi_code不能为空" };
                return dto;
            }

            //保存到本地数据库

            TokenMeiTuanDto token = await this.GetMtsgToken(isSoldOutDto.app_poi_code);
            if (token == null)
            {
                dto.error = new Error() { code = -1, msg = "token不能为空" };
                return dto;
            }

            if (string.IsNullOrEmpty(token.access_token))
            {
                dto.error = new Error() { code = token.status, msg = token.message };
                return dto;
            }

            this.httpClientMeiTuanShanGou.GetTimeStamp();
            return await this.httpClientMeiTuanShanGou.PostIsSoldOut(isSoldOutDto);
        }

        private async Task<DataDto> PostIsSoldOut(long app_poi_code, string ID)
        {
            DataDto dto = new DataDto();
            IsSoldOutDto isSoldOutDto = new IsSoldOutDto();
            isSoldOutDto.app_poi_code = app_poi_code;

            List<MedicineData> medicineDatas = new List<MedicineData>();
            medicineDatas.Add(
                new MedicineData() { app_medicine_code = ID, is_sold_out = 0 }
          );
            isSoldOutDto.medicine_data = medicineDatas;
            dto = await this.httpClientMeiTuanShanGou.PostIsSoldOut(isSoldOutDto);

            return dto;
        }


        private string CheckMtsg(ProductInfoMtsgEntity product, List<ShopMapEntity> shops, out ShopMapEntity shop, out string CategoryName)
        {

            string msg = "";
            shop = shops.Where<ShopMapEntity>(ww => ww.Platform == PlatformEnum.Mtsg).FirstOrDefault();
            if (shop == null)
            {
                msg += "美团闪购没有维护店铺信息";
            }

            //price
            int scale = 0; //小数位数
            decimal price = product.Price;

            string[] parr = price.ToString().Split('.');

            if (parr.Length > 1)
            {
                scale = parr[1].Length;
            }
            if (scale > 2 || price < 0 || price > (Decimal)30000.00)
            {
                msg += "最多支持2位小数，不能为负数，最大支持30000.00";
            }

            //stock
            int stock = product.Stock;
            if (stock < 0 || stock > 99999)
            {
                msg += "不能为负数或小数，最大允许99999";
            }

            //category_code
            CategoryName = "";
            if (string.IsNullOrEmpty(CategoryName) && shop != null)
            {
                CategoryName = shop.CategoryName;
            }

            if (string.IsNullOrEmpty(CategoryName))
            {
                msg += "分类名称不能为空";
            }

            return msg;
        }

        private async Task<DataDto> SaveMtsg(ProductInfoMtsgEntity product, List<ShopMapEntity> shops)
        {
            DataDto dto = new DataDto();

            ShopMapEntity shop = null;
            string CategoryName = "";
            string msg = this.CheckMtsg(product, shops, out shop, out CategoryName);

            if (msg != "")
            {
                dto.error = new Error() { code = -1, msg = msg };
                return dto;
            }

            if(shop.CompanySN == 0)
            {
                dto.error = new Error() { code = -1, msg = "公司SN不能为0" };
                return dto;
            }

            product.CompanySN = shop.CompanySN;
            product.CategoryCode = "";
            product.CategoryName = CategoryName;
            long app_poi_code = shop.app_poi_code;
            product.ShopSN = app_poi_code;
            product.app_medicine_code = product.ProductSN;

           //上传美团
           TokenMeiTuanDto token = await this.GetMtsgToken(app_poi_code);
            if (token == null)
            {
                dto.error = new Error() { code = -1, msg = "token不能为空" };
                return dto;
            }

            if (token.error != null)
            {
                dto.error = new Error() { code = token.status, msg = token.error.msg };
                return dto;
            }

            product.is_sold_out = 0;
            product.app_poi_code = app_poi_code;

            this.httpClientMeiTuanShanGou.GetTimeStamp();

            //判断数据库里是否有SN
            ProductInfoMtsgEntity productInfoEntity = this.medicineBLL.Get(product.ProductSN, app_poi_code);
            if (productInfoEntity != null) //如果数据库已经存在,只有上架，不需要创建产品
            {
                product.ID = productInfoEntity.ID;
                dto = await this.PostIsSoldOut(app_poi_code, product.ID);
                if (dto.error == null)
                {
                    int result = this.medicineBLL.Save(product);
                }
                else
                {
                    base.WriteInformation("SaveMtsg>data", dto.data);
                }
            }
            else
            {
                if (string.IsNullOrEmpty(product.ID))
                {
                    product.ID = $"{product.ProductSN}";
                }

               
                MedicineInfo medicine = new MedicineInfo();
                medicine.app_medicine_code = product.ID;
                medicine.app_poi_code = app_poi_code;
                medicine.category_code = product.CategoryCode;
                medicine.category_name = product.CategoryName;
                //medicine.ctime = DateTimeUtil.DateTimeToTimeStamp(DateTime.Now);
                medicine.is_sold_out = product.is_sold_out;
                medicine.medicine_no = product.LiceseId;
                medicine.medicine_type = 1;
                medicine.name = product.ProductName;
                medicine.price = (float)product.Price;
                medicine.sequence = 0;
                medicine.spec = product.Spec;
                medicine.stock = product.Stock.ToString();
                medicine.upc = product.Upc;
                //medicine.utime = DateTimeUtil.DateTimeToTimeStamp(DateTime.Now);

                DataDto dataDto = await this.httpClientMeiTuanShanGou.MedicineSave(medicine);

                Error error = dataDto.error;
                if (error != null)
                {
                    //3008: 已经存在    901:Upc 已经存在 
                    if (error.code == 3008)
                    {
                        dataDto = await PostIsSoldOut(app_poi_code, product.ID);
                        if(dataDto.error != null)
                        {
                            error.msg += " " + dataDto.error.msg;
                        }
                      
                    }
                    else if (error.code == 901)
                    {
                        error = dataDto.error;
                    }
                    dto.error = error;

                    if( error.code == 3008 || error.code == 901)
                    {
                        int result = this.medicineBLL.Save(product);
                    }
                   
                }
                else
                {
                    if (dataDto.data == "ok")
                    {
                        int result = this.medicineBLL.Save(product);
                    }
                    else
                    {
                        base.WriteInformation("SaveMtsg>data", dto.data);
                    }
                }

            }

            return dto;
        }

      
        private async Task<DataDto> UpdateMtsgStock(List<ShopMapEntity> shopList, List<UpdateStockQty> erpStocks)
        {
            DataDto dto = new DataDto();

            ShopMapEntity shopMtsg = shopList.Where(oo => oo.Platform == PlatformEnum.Mtsg)
                    .First();
            string strMsg = "";
            if (shopMtsg != null)
            {
                long app_poi_code = shopMtsg.app_poi_code; //门店ID
                TokenMeiTuanDto token = await this.GetMtsgToken(app_poi_code);
                if (token.status != 0)
                {
                    return dto;
                }

                ProductStock mtsgSock = new ProductStock(); //mtsg的值
                mtsgSock.app_poi_code = app_poi_code;

                List<StockQty> medicine_data = new List<StockQty>();
                mtsgSock.medicine_data = medicine_data;

                //从数据库获取产品映射集合
                List<ProductInfoMtsgEntity> productlist = this.medicineBLL.Query(app_poi_code);
                foreach (UpdateStockQty stock in erpStocks)
                {
                    var list2 = productlist.Where(oo => oo.ProductSN == stock.ProductSN);
                    int count = list2.Count();
                    if (count > 0)
                    {
                        ProductInfoMtsgEntity product = list2.First();
                        if (product != null)
                        {
                            medicine_data.Add
                                (new StockQty
                                {
                                    app_poi_code = app_poi_code,
                                    app_medicine_code = product.ID,
                                    stock = stock.Qty
                                });
                        }
                    }
                    else
                    {
                        strMsg += $"ProductSN:{stock.ProductSN}不存在,请上传或者绑定";
                    }
                }

                this.httpClientMeiTuanShanGou.GetTimeStamp();
                dto = await this.httpClientMeiTuanShanGou.Stock(mtsgSock);
                if (dto.error != null)
                {
                    strMsg += dto.error.msg;
                }
            }
            else
            {
                strMsg = "美团闪购没有配置门店";
            }

            if (strMsg != "")
            {
                dto.error = new Error() { code = -1, msg = strMsg };
            }
            return dto;
        }

        #endregion

    }
}
